package com.hopu.v1.utils;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient;
import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsRequest;
import darabonba.core.client.ClientOverrideConfiguration;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author: YwaiX
 * @Version: 1.0
 * @Date: Created in 2024-09-14 10:18:24
 * @Description:
 */

public class SendMessage {
    
    public static String send(String phone) {
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                .accessKeyId("LTAI5tDvc3ECLTL8me2iZNAH")
                .accessKeySecret("jJremJMkto9LRydt5V0xN8F7XukGPY")
                .build());
        
        AsyncClient client = AsyncClient.builder()
                .region("cn-hangzhou") // Region ID
                .credentialsProvider(provider)
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                .setEndpointOverride("dysmsapi.aliyuncs.com")
                )
                .build();
        
        String code = SendRandomNumber.randomNumber();
        
        SendSmsRequest sendSmsRequest = SendSmsRequest.builder()
                .signName("阿里云短信测试")
                .templateCode("SMS_154950909")
                .phoneNumbers(phone)
                .templateParam("{\"code\":\"" + code + "\"}")
                .build();
        
        client.sendSms(sendSmsRequest);
        
        client.close();
        
        return code;
    }
}
